/**
 * @license
*
* PreProcessing is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PreProcessing is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PreProcessing.  If not, see <http://www.gnu.org/licenses/>.
* 
*/

/**
 * @file Log.java
 * 
 * @brief Log.java is Part of the SmartGrid system containing the log of 
 *        each device's power usage.  
 * 
 * @author Grant Hewton
 * @version 1
 */
package SmartGrid;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @class Log 
 * 
 * @brief class to record device power usage.
 * 
 * A record of each devices usage is made using deviceID, timestamp start/end 
 * and the power consumed for that time
 * 
 * 
 */
public class Log {
    private int logID;
    private String logStartDateTime;
    private String logEndDateTime;
    private int logDeviceID;
    private double powerConsumed;
    
    private static int numberOfLogs = 0;
        

    /** 
     * @brief Log constructor
     * 
     * Constructs a new log file of type Log
     */
    public Log(int deviceID) 
    {        
        logDeviceID = deviceID;
        logStartDateTime = getDateTime();
        logID = ++numberOfLogs;
    }

    public Log() {
    }
    /**
     * @brief setLogID
     * @param newLogID used to set the new logID 
     * 
     */
   /* public void setLogID(int newLogID) 
    {
        
        logID = newLogID;
        //this.doConversion();
    }*/
        
    /**
     * @brief set the logEndDateTime
     * The current timestamp will be recorded to the logEndDateTime
     * 
     */    
    public void setLogEndDateTime()
    {
        logEndDateTime = getDateTime();
    }
    
    /**
     * @brief set the powerConsumed
     * The total amount of power for the time period will be recorded
     * @param powerUsed passes in the value of used power
     */    
    public void setPowerConsumed(double powerUsed)
    {
        powerConsumed = powerUsed;
    }    
    
    /**
     * @brief getlogID 
     * Get the logID of the object
     * @return logID is returned as an int
     */    
    public int getlogID() 
    {
        return logID;
    }

    /**
     * @brief getDateTime
     * The current timestamp will formatted  (dd/mm/yyyy hh/mm/ss) and returned
     * @param 
     */
    public String getDateTime() 
    {
        java.sql.Timestamp now = new java.sql.Timestamp(System.currentTimeMillis());
        String dn = now.toString();
       
        return dn.substring(0, dn.lastIndexOf("."));
    }

    public static int getNumberOfLogs() {
        return numberOfLogs;
    }

    public String getLogEndDateTime() {
        return logEndDateTime;
    }

    public String getLogStartDateTime() {
        return logStartDateTime;
    }

    public double getPowerConsumed() {
        return powerConsumed;
    }

    public int getLogID() {
        return logID;
    }

    public int getLogDeviceID() {
        return logDeviceID;
    }
    
    /**
     * @brief Pint the Log to string
     * The current Log class properties will be formatted and returned
     * 
     */
    @Override
    public String toString() 
    {        
        return "Log ID: " + this.logID + "\tDeviceID: " + logDeviceID;
    }
    
}
